package wsi.subgraph.entity;

import java.util.ArrayList;
import java.util.List;

import org.rygh.core.face.IHasKey;
import org.rygh.semantic.model.ex.PredicatePath;

import wsi.subgraph.tree.EntityLeaf;

public class EntityGroup implements IHasKey<String> {

	private final PredicatePath predicatePath;
	private final List<EntityLeaf> nodes = new ArrayList<>();

	public EntityGroup(PredicatePath path) {
		this.predicatePath = path;
	}

	public void add(EntityLeaf node) {
		nodes.add(node);
	}

	public int getDistance() {
		return predicatePath.size();
	}

	@Override
	public String getKey() {
		return predicatePath.getKey();
	}

	public List<EntityLeaf> getNodes() {
		return nodes;
	}

	public PredicatePath getPredicatePath() {
		return predicatePath;
	}

	public String toNodeString() {
		StringBuilder sbuilder = new StringBuilder();

		for (EntityLeaf n : nodes)
			sbuilder.append(String.format("%s; ", n.getValue().getValue()
					.getValue()));

		return sbuilder.toString();
	}

	@Override
	public String toString() {
		StringBuilder sbuilder = new StringBuilder();

		sbuilder.append(predicatePath.getKey());
		sbuilder.append(String.format(" (%d):\n\t", nodes.size()));

		for (EntityLeaf n : nodes)
			sbuilder.append(String.format("%s; ", n));

		return sbuilder.toString();
	}
}
